email me at borlaj@portlandschools.org

Loading
notes previous (14/<14) submit the dump links  
 

Frogger

 

Working with just the Bar class:

  1. Get bar to move (this will only happen when keys are pressed
  2. Get bar to screen wrap or bounce
  3. Get bar to have a random speed (so speed should be a global)
  4. Get bar to have a random color
  5. Get a random direction:
    • Create a global variable boolean isMovingRight
    • In the constructor (public Bar(int y){
      • make global isMovingRight randomly left (false) or right (true)

Working with the BarTester

  1. Make another Bar - bar2 and move and draw that
  2. Make it an array of Bars do either [1 is easier]
    1. Bar allBars[]={new Bar(100),new Bar(200), ....}
    2. or Bar allBars[5]=new Bar[5]; then allBars[0]=new Bar(20); etc
  3. Then move and draw each one:
for (int i=0; i<allBars.length; i++)
{
              allBars[i].moveBar();
              allBars[i].drawBar(g);
              //check for collissions
}

 

Working with Frogger

  1. Move stuff from BarTester in to Frogger (stuff that creates an array of bars and moves, draws them
  2. Work with Frog
    1. Get move to work
  3. Add collission to the bar class

 

 

 

Changing sprites to use images is really easy, which just load the image with the constructor

  • super(50,100,20,30, "mario.jpg");

Sprite has a build in method: drawImage(g) that will automatically draw the image at g. So in the main Frogger class, if Frog had an image loaded:

  • myFrog.drawImage(g); //would call the drawImage of sprite